﻿Imports System.Web.Http
Imports Microsoft.Owin
Imports Microsoft.Owin.Security.OAuth
Imports Owin

<Assembly: OwinStartup(GetType(AngularJSAuthentication.API.Startup))> 
Namespace AngularJSAuthentication.API

    Public Class Startup

        Public Sub Configuration(app As IAppBuilder)
            Dim config As New HttpConfiguration()
            ConfigureOAuth(app)
            Register(config)
            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll)
            app.UseWebApi(config)
        End Sub


        Public Sub ConfigureOAuth(app As IAppBuilder)
            Dim OAuthServerOptions As New OAuthAuthorizationServerOptions() With {
                 .AllowInsecureHttp = True,
                .TokenEndpointPath = New PathString("/token"),
                .AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
                .Provider = New SimpleAuthorizationServerProvider()
            }

            ' Token Generation
            app.UseOAuthAuthorizationServer(OAuthServerOptions)
            app.UseOAuthBearerAuthentication(New OAuthBearerAuthenticationOptions())

        End Sub
    End Class

End Namespace